home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / FindIcon / Get_normal_folder_icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-26  |  2.7 KB  |  90 lines  |  [TEXT/KAHL]

  1. #include <Finder.h>
  2. #include <Folders.h>
  3. #include "Get_normal_folder_icon.h"
  4. #include <exceptions.h>
  5. #include "Get_resource_icons.h"
  6. #include "Copy_each_icon.h"
  7.  
  8. static Boolean Match_special_dirID( OSType folder_type, long dirID );
  9.  
  10. /*    ------------------------------------------------------------------
  11.     Get_normal_folder_icon            Create an icon suite for a folder
  12.                                     that does not have a custom icon.
  13.     ------------------------------------------------------------------
  14. */
  15. OSErr    Get_normal_folder_icon(
  16. /* --> */    CInfoPBRec    *cpb,
  17. /* --> */    IconSelectorValue    icon_selector,
  18. /* <-- */    Handle    *the_suite
  19. )
  20. {
  21.     OSErr    err;
  22.     short    found_vRefNum, icon_id;
  23.     long    found_dirID, dirID;
  24.     short    save_resfile;
  25.     
  26.     dirID = cpb->dirInfo.ioDrDirID;
  27.     
  28.     if ( (FindFolder( kOnSystemDisk, kSystemFolderType, kDontCreateFolder,
  29.         &found_vRefNum, &found_dirID ) == noErr)
  30.         && (found_vRefNum == cpb->dirInfo.ioVRefNum)
  31.         && (found_dirID == dirID) )
  32.     {
  33.         icon_id = systemFolderIconResource;
  34.     }
  35.     else if ( (found_vRefNum == cpb->dirInfo.ioVRefNum) &&
  36.         (found_dirID == cpb->dirInfo.ioDrParID) )
  37.     {
  38.         /*
  39.             The folder is a subfolder of the System Folder, so it
  40.             might be one with a special icon.
  41.         */
  42.         if ( Match_special_dirID( kAppleMenuFolderType, dirID ) )
  43.             icon_id = appleMenuFolderIconResource;
  44.         else if ( Match_special_dirID( kControlPanelFolderType, dirID ) )
  45.             icon_id = controlPanelFolderIconResource;
  46.         else if ( Match_special_dirID( kExtensionFolderType, dirID ) )
  47.             icon_id = extensionsFolderIconResource;
  48.         else if ( Match_special_dirID( kPreferencesFolderType, dirID ) )
  49.             icon_id = preferencesFolderIconResource;
  50.         else if ( Match_special_dirID( kPrintMonitorDocsFolderType, dirID ) )
  51.             icon_id = printMonitorFolderIconResource;
  52.         else if ( Match_special_dirID( kStartupFolderType, dirID ) )
  53.             icon_id = startupFolderIconResource;
  54.         else if ( Match_special_dirID( kFontsFolderType, dirID ) )
  55.             icon_id = fontsFolderIconResource;
  56.     }
  57.     else
  58.     {
  59.         /* These attribute bits are described in TN 301. */
  60.         if ((cpb->dirInfo.ioFlAttrib & 0x08) != 0)
  61.             icon_id = mountedFolderIconResource;
  62.         else if ((cpb->dirInfo.ioFlAttrib & 0x20) != 0)
  63.             icon_id = sharedFolderIconResource;
  64.         else if ((cpb->dirInfo.ioFlAttrib & 0x04) != 0)
  65.             icon_id = ownedFolderIconResource;
  66.         else
  67.             icon_id = genericFolderIconResource;
  68.     }
  69.     
  70.     save_resfile = CurResFile();
  71.     UseResFile(0);
  72.     err = Get_resource_icons( the_suite, icon_id, icon_selector );
  73.     
  74.     UseResFile( save_resfile );
  75.     
  76.     return err;
  77. }
  78.  
  79. static Boolean Match_special_dirID( OSType folder_type, long dirID )
  80. {
  81.     OSErr    err;
  82.     short    found_vRefNum;
  83.     long    found_dirID;
  84.     
  85.     err = FindFolder( kOnSystemDisk, folder_type, kDontCreateFolder,
  86.             &found_vRefNum, &found_dirID );
  87.     
  88.     return (err == noErr) && (found_dirID == dirID);
  89. }
  90.